<template>
<!-- 天御防护 -->
  <div class="safety">
    <h3>{{$t("configLazyLoad.safetyProtectionConfig.title")}}</h3>
    <el-switch
    v-model="useTianyu"
    class="safetyProtection"
    :active-text="$t('configLazyLoad.public.open')"
    :inactive-text="$t('configLazyLoad.public.close')"
    @change="safetyChange">
    </el-switch>
  </div>
</template>

<script>
export default {
    data(){
        return{
            useTianyu: false,
        }
    },
    methods:{
        fetchData(){
            this.$store.dispatch('getGlobalSetById', {}).then((resp) => {
                if (resp.success && resp.row) {
                    this.useTianyu = resp.row.useTianyu || false
                }
            })
        },
        safetyChange(val){
            this.$store.dispatch('saveGlobalSet', { useTianyu: this.useTianyu }).then((rep) => {
                if (rep.success) {
                    this.$message.success(this.$t('config.channel.configSuccess'))
                } else {
                    this.$message.error(this.$t('qualityCheck.saveFali'))
                }
            })
        }
    },
    mounted(){
        this.fetchData()
    }

}
</script>

<style lang="stylus" scoped>
@import "../../../../assets/common.styl"
.safety
   height calc(100vh - 130px)
   padding 20px
   overflow auto
   .safetyProtection
    margin-top 10px
</style>
